package zkk.com.mengqu.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.List;

import zkk.com.mengqu.R;
import zkk.com.mengqu.models.Address;

/**
 * Created by 40955 on 2017/8/21.
 */

public class AddressAdapter extends BaseAdapter {
    private Context context;
    private List<Address> list;

    public AddressAdapter(Context context, List<Address> list){
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder = null;
        if (view == null){
            view = LayoutInflater.from(context).inflate(R.layout.item_address, null);
            holder = new ViewHolder(view);
            view.setTag(holder);
        }else{
            holder = (ViewHolder) view.getTag();
        }

        holder.address.setText(list.get(i).getAddress());
        holder.userName.setText(list.get(i).getName());
        holder.userPhone.setText(list.get(i).getPhone());

        return view;
    }

    class ViewHolder{
        private TextView address, userName, userPhone;
        private RelativeLayout addressItem;
        public ViewHolder(View view){
            address = (TextView)view.findViewById(R.id.tx_address);
            userName = (TextView)view.findViewById(R.id.tx_address_user);
            userPhone = (TextView)view.findViewById(R.id.tx_address_phone);

            addressItem = (RelativeLayout)view.findViewById(R.id.rl_address);
        }
    }
}
